<?php

/**
 * main actions.
 *
 * @package    maxgifts
 * @subpackage main
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class mainActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    
  }
  
  public function executeGetPremium(sfWebRequest $request)
  {
      
  }
  
  public function executePrizeList(sfWebRequest $request)
  {
    
  }
  
  public function executeGamesList(sfWebRequest $request)
  {
    
  }
  
  public function executeRegister(sfWebRequest $request)
  {
      $this->accountFailure = '';
      $this->formText = '';
  }
  
  public function executeLogin(sfWebRequest $request)
  {
    $this->validationBar = '';
    if(!UserConf::getInstance()->isUserLoaded())
    {
        $login = $request->getParameter('login');
        $password = $request->getParameter('password');
        if(($login != NULL && $password == NULL) || ($login == NULL && $password != NULL))
        {
            $this->validationBar = '<div class="failure">Nie wypełniono wszystkich pól formularza.</div>';
        }
        else if($login != NULL && $password != NULL)
        {
            if(UserConf::getInstance()->registerUser($login, $password))
            {
                $this->validationBar = '<div class="success">Zalogowano poprawnie. Za 3 sekundy zostaniesz przeniesiony.</div>';
                $this->redirect('main/account');             
            }
            else
            {
                $this->validationBar = '<div class="failure">Podane dane są nieprawidłowe.</div>';
            }
        }
    }
  }
  
  public function executeAccount(sfWebRequest $request)
  {
      if(UserConf::getInstance()->isUserLoaded())
      {
          $this->user = UserConf::getInstance()->getUser();
      }
      else
      {
          $this->redirect('main/login');
      }
  }
  
  public function executeLogout(sfWebRequest $request)
  {
    if(UserConf::getInstance()->isUserLoaded())
    {
        UserConf::getInstance()->unregisterUser();
    }
    else
    {
        $this->redirect('main/login');
    }
  }
}
